import orderApi from '@/config/server/api/order.js'
import dt from '@dt/dt'

function roomList(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.room.list.fetch(info)
}

function roomDel(commissionDetailId) {
  return orderApi.commission.initiate.room.del.fetch({ commissionDetailId })
}

function roomClear(commissionId) {
  return orderApi.commission.initiate.room.clear.fetch({ commissionId })
}

function roomAdd(commissionId, orderIds) {
  let info = {
    commissionId,
    orderIds,
    housesId: dt.buildInfo().housesId
  }
  return orderApi.commission.initiate.room.add.fetch(info)
}

function create(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.create.fetch(info)
}

function update(info) {
  return orderApi.commission.initiate.update.fetch(info)
}

function del(commissionId) {
  return orderApi.commission.initiate.del.fetch({ commissionId })
}

function detail(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.detail.fetch(info)
}

function list(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.list.fetch(info)
}

function submit(info) {
  return orderApi.commission.initiate.submit.fetch(info)
}

function roomImport(commissionId) {
  let info = { commissionId }
  info.housesId = dt.buildInfo().housesId
  info.fileName = 'file'
  let upload = orderApi.commission.initiate.room.import
  upload.setData(info)
  return upload
}

function roomExport(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.room.export.fetch(info)
}

function exportInfo(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.export.fetch(info)
}

function commissionTemplate(info) {
  info.housesId = dt.buildInfo().housesId
  return orderApi.commission.initiate.commissionTemplate.fetch(info)
}

function commissionImport() {
  let info = {
    housesId: dt.buildInfo().housesId
  }
  let upload = orderApi.commission.initiate.commissionImport
  upload.setData(info)
  return upload
}

function commissionClear() {
  return orderApi.commission.initiate.commissionClear.fetch({
    housesId: dt.buildInfo().housesId
  })
}

function revocation(commissionId) {
  return orderApi.commission.initiate.revocation.fetch({ commissionId })
}

export default {
  roomList,
  roomDel,
  roomClear,
  roomAdd,
  roomImport,
  roomExport,
  create,
  update,
  del,
  detail,
  list,
  submit,
  exportInfo,
  commissionTemplate,
  commissionImport,
  commissionClear,
  revocation
}
